package org.neuedu.ssmp.crm.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.neuedu.ssmp.crm.entity.CustomerLevel;
import org.neuedu.ssmp.crm.entity.vo.ResponseEntity;
import org.neuedu.ssmp.crm.service.ICustomerLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/basic")
public class CustomerLevelController {
    @Autowired
    private ICustomerLevelService iCustomerLevelService;

    @RequestMapping("/findAll")
    public List<CustomerLevel> findAll(){
        List<CustomerLevel> list = iCustomerLevelService.list();
        return list;
    }

    @RequestMapping("/add")
    public ResponseEntity add(@RequestBody CustomerLevel customerLevel){
        return iCustomerLevelService.addCustomerLevel(customerLevel);
    }

    @RequestMapping("/updateById")
    public void edit(@RequestBody CustomerLevel customerLevel){
        System.out.println(customerLevel.toString());
        iCustomerLevelService.updateById(customerLevel);
    }

    @RequestMapping("/delid/{id}")
    public void deleteById(@PathVariable String id){
        iCustomerLevelService.removeById(Integer.parseInt(id));
    }

    @RequestMapping("/query")
//    public void query(@RequestParam(value = "category") String category,@RequestParam String entry,@RequestParam String valu){
    public List<CustomerLevel> query(@RequestBody CustomerLevel customerLevel){
        System.out.println("第一次输出"+customerLevel.toString());
        String name = customerLevel.getName();
        System.out.println(name);
        LambdaQueryWrapper<CustomerLevel> lambdaQueryWrapper = Wrappers.lambdaQuery();
        LambdaQueryWrapper<CustomerLevel> category1 = lambdaQueryWrapper.like(CustomerLevel::getName,name);
        return iCustomerLevelService.list(lambdaQueryWrapper);
    }
}
